<template>
    <view class="container">
        <!-- <view class="info">
            <view class="info-name">
                <view class="name">
                    姓名
                </view>
                <input type="text" class="input" placeholder="请输入您的姓名" v-model="userName" />
            </view>
            <view class="info-phone">
                <view class="phone">
                    手机号
                </view>
                <input type="text" :value="userPhone" class="input" placeholder="获取手机号" disabled />
                <button class="obtain" plain="true" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
                    获取手机号
                </button>
            </view>
        </view> -->
        <div class="imgbox">
            <img class="img" src="../../static/loginlogo.png" alt="">
            <div class="item"></div>
            <div class="item bacblueone"></div>
            <div class="item bacbluetwo"></div>
        </div>
        <view style="text-align: center; margin-top: 20rpx; font-weight: bold;">仅供子弹人力云内部员工使用</view>
        <view class="empower-box">
            <button open-type="chooseAvatar" class="long-btn short-btn" @chooseavatar="onChooseAvatar">
                账号登录
            </button>
        </view>
        <view class="tip" style="display: flex;align-items: center;justify-content: center;"
            @click="isselect = !isselect">
            <!-- <checkbox color="#d95757" style="transform:scale(0.5);" :checked="isselect" class="round red" /> -->
            <view>
                <view>小程序仅供特定人员使用，并同意</view>
                <view>
                    <text class="agreement blue">《子弹CRM平台用户服务协议》</text>、
                    <text class="agreement blue">《隐私协议》</text>
                </view>
            </view>
        </view>
    </view>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import global from '@/utils/global'
import user from '@/utils/user'
import { encryptedPhoneData, register, uploadUrl } from '@/api/base'
import { toast, getUserProfile } from '@/utils/util'
import { parse } from '@typescript-eslint/parser'
const userName = ref('')
const userPhone = ref('')
const urlAdd = ref('')
const isselect = ref(false)
const onRegister = () => {
    if (!userName.value) {
        toast('请输入姓名')
        return
    }
    if (!userPhone.value) {
        toast('请输入手机号')
        return
    }
    const info = getUserProfile()
    console.log(user.sex, 'user.sexuser.sex')
    user.sex = info.gender
    register({
        openId: user.openId,
        salesName: userName.value,
        realName: userName.value,
        salesHeadUrl: user.avatarUrl as string,
        // phone: userPhone.value,
        sex: user.sex as number,
        idCardNo: ''
    })
    uni.redirectTo({ url: '/pages/toExamine/toExamine?type=success&title=等待审核' })
}

onLoad(() => {
    uni.hideHomeButton()
})
// onShow(() => {
//     console.log('调用了吗')
//     // upLoad()
// })
const getPhoneNumber = async (event: { detail: { encryptedData: string, iv: string, errMsg: string } }) => {
    console.log(event, 'event')
    if (event.detail.errMsg === 'getPhoneNumber:fail user deny') {
        return 1
    } else {
        const data = {
            appId: global.appId,
            encryptedData: event.detail.encryptedData,
            iv: event.detail.iv,
            openid: user.openId
        }
        const phone = await encryptedPhoneData(data)
        userPhone.value = phone.phoneNumber
    }
}

const onChooseAvatar = (e: any, index: number) => {
    // uni.chooseImage({
    //   success: (chooseImageRes) => {
    //     console.log(chooseImageRes,'chooseImageReschooseImageRes')
    //     const tempFilePaths = chooseImageRes.tempFilePaths;
    return new Promise((resolve, reject) => {
        uni.uploadFile({
            url: global.baseUrl + '/api/v1/crm/file-detail/upload', // 仅为示例，非真实的接口地址
            filePath: e.target.avatarUrl,
            name: 'file',
            formData: {
                user: 'test'
            },
            success: (uploadFileRes) => {
                console.log(uploadFileRes, '11111')
                user.avatarUrl = JSON.parse(uploadFileRes.data).data.fileUrl
                uni.navigateTo({ url: "/pages/realNameAuthentication/realNameAuthentication" })
                //   onRegister()
            },
            fail: (err) => {
                console.log(err, 'errerrerrerrerr')
            }
        })
        //   })
        // }
    })
}

</script>
<style lang="scss" scoped>
.container {
    background: #fafafc;
    height: 100vh;
}

.info {
    background: #ffffff;
}

.info-name,
.info-phone {
    padding: 30rpx 40rpx;
    box-sizing: border-box;
    display: flex;
    align-items: center;

    .phone,
    .name {
        color: #202536;
        font-size: 32rpx;
        width: 100rpx;
        flex: none;
    }

    .input {
        margin-left: 60rpx;
        width: 100%;
        font-size: 32rpx;
    }

    .obtain {
        flex: none;
        color: #ff7e68;
        font-size: 28rpx;
        border: none;
    }
}

.long-btn {
    background: #3E5FF5;
    margin-top: 460rpx;
}

.tip {
    color: #A6A8AF;
    font-size: 24rpx;
    line-height: 6vw;
    text-align: center;
    margin-top: 3vw;
    position: static;
}

.link {
    color: #00D679;
}

.short-btn {
    width: 420rpx;
}

.empower-box {
    display: flex;
    align-items: center;
    justify-content: center;
}

.blue {
    color: #3E5FF5;
}

.imgbox {
    position: relative;
    width: 100%;
    height: 500rpx;
    box-sizing: border-box;
    display: flex;

    .item {
        flex: 1;
        height: 250rpx;
    }

    .bacblueone {
        opacity: 0.06;
        background: linear-gradient(0deg, rgba(62, 95, 245, 0.00) 0%, #2A50FA 100%, );
    }

    .bacbluetwo {
        opacity: 0.06;
        background: linear-gradient(0deg, rgba(42, 80, 250, 0.00) 0%, #2A50FA 100%);
    }

    .img {
        bottom: 30rpx;
        left: 32%;
        position: absolute;
        width: 280rpx;
        height: 234rpx;
    }
}
</style>
